#!/bin/bash

if [ $# -lt 1 ]; then
   echo "$0 <project> [action] [branch]"
   echo "action: update, reindex, add"
   exit 1
fi

project=$1
action=$2
branch=${3:-"master"}

if [ ! -d opengrok/src/${project} ]; then
    echo "project ${project} not exists, abort!"
    exit 1
fi

if [ "$action" == "update" ]; then
    pushd opengrok/src/${project}
    git pull origin ${branch}
    popd
fi

if [ "$action" == "add" ]; then
        ./update_index_per_project.sh ${project} add
else 
	rm -rf opengrok-new/data/index/${project}
	rm -rf opengrok-new/data/xrfef/${project}
	./update_index_per_project.sh ${project}
fi

echo "Done"

